package cn.ld.module.ai.dal.mapper.chat;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.ai.controller.admin.chat.vo.conversation.AiChatConversationPageInVO;
import cn.ld.module.ai.dal.entity.chat.AiChatConversationEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * AI 聊天对话 Mapper
 *
 * @author 蓝盾
 */
@Mapper
public interface AiChatConversationMapper extends BaseMapperX<AiChatConversationEntity> {

    default List<AiChatConversationEntity> selectListByUserId(Long userId) {
        return selectList(AiChatConversationEntity::getUserId, userId);
    }

    default List<AiChatConversationEntity> selectListByUserIdAndPinned(Long userId, boolean pinned) {
        return selectList(new LambdaQueryWrapperX<AiChatConversationEntity>()
                .eq(AiChatConversationEntity::getUserId, userId)
                .eq(AiChatConversationEntity::getPinned, pinned));
    }

    default PageResult<AiChatConversationEntity> selectChatConversationPage(AiChatConversationPageInVO pageInVO) {
        return selectPage(pageInVO, new LambdaQueryWrapperX<AiChatConversationEntity>()
                .eqIfPresent(AiChatConversationEntity::getUserId, pageInVO.getUserId())
                .likeIfPresent(AiChatConversationEntity::getTitle, pageInVO.getTitle())
                .betweenIfPresent(AiChatConversationEntity::getCreateTime, pageInVO.getCreateTime())
                .orderByDesc(AiChatConversationEntity::getId));
    }

}
